#函数的作用域
# 全局变量（变量名大写）

#
# COUNTRY = "中国"
# CITY_LIST = ["北京","上海","深圳"]
#
# def download():
#     # 局部变量
#     url = "http://www.xxx.com"
#
# print(COUNTRY,CITY_LIST)


#在局部作用域中读取全局变量
# COUNTRY = "中国"
# CITY_LIST = ["北京", "上海", "深圳"]
#
#
# def download():
#     url = "http://www.xxx.com"
#     print(url)
#     print(COUNTRY)
#     print(CITY_LIST)
#
# print(COUNTRY)
# download()

#局部变量和全局变量的变量名相同
# CITY_LIST = ["北京", "上海", "深圳"]
#
# def download():
#     url = "http://www.xxx.com"
#     CITY_LIST = ["河北", "河南", "山西"]
#     print(url)
#     print(CITY_LIST)
#
# print(CITY_LIST)
# download()

#global关键词
# a=2
# def fun():
#     print(a)  #对全局变量的读取
#
# fun()

# a=[2,"xiaofeng",(1,5)]
# print(a)
# def fun():
#     a.append("liu")  #对内部元素的修改
#     a[2]=3
# fun()
# print(a)

#无法对全局变量进行重新赋值
# a=2
# def fun():
#     a=9
#     print(a)
# fun()
# print(a)


#在局部作用域中修改全局变量
# a=2
# def fun():
#     global a
#     a=9
#     print(a)
# print(a)
# fun()
# print(a)
# 1. 在全局作用域定义了函数func
# def func():
#     print("你好")
# # 2. 在全局作用域找到func函数并执行。
# func()
#
# # 3.在全局作用域定义了execute函数
# def execute():
#     print("开始")
#     # 优先在当前函数作用域找func函数，没有则向上级作用域中寻找。
#     func()
#     print("结束")
#
#
# # 4.在全局作用域执行execute函数
# execute()